package cliente.GUI;

import java.awt.*;
import javax.swing.*;
import servidor.Sensor;

public class PanelSensor extends JPanel
{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * @param args
	 */
	
	JLabel nombre;
	JButton on;
	JButton off;
	JButton valAct;
	JButton historico;
	
	public PanelSensor(Sensor s)
	{
		on = new JButton("ON");
		off = new JButton("OFF");
		valAct = new JButton("VALOR ACTUAL");
		historico = new JButton("HISTORICO");
		if(s != null)
			nombre = new JLabel("       " + s.getDescripcion());
		else
		{
			nombre = new JLabel("       ");
			on.setEnabled(false);
			off.setEnabled(false);
			valAct.setEnabled(false);
			historico.setEnabled(false);
		}
		
		JPanel p = new JPanel();
		p.setLayout(new GridLayout(1, 3));
		p.add(nombre);
		JPanel n = new JPanel();
		n.add(on);
		p.add(n);
		JPanel f = new JPanel();
		f.add(off);
		p.add(f);
		
		this.setLayout(new GridLayout(2, 1));
		this.add(p);
		JPanel h = new JPanel();
		h.add(valAct);
		h.add(historico);
		this.add(h);
	}
	
	public void cargarSensor(Sensor s)
	{
		nombre.setText("       " + s.getDescripcion());
		on.setEnabled(true);
		off.setEnabled(true);
		historico.setEnabled(true);
		valAct.setEnabled(true);
	}
	
	public static void main(String[] args)
	{
		// TODO Auto-generated method stub
		JFrame f = new JFrame();
		f.setLayout(new BorderLayout());
		Sensor s = new Sensor();
		s.setDescripcion("Humedad");
		s.setEstado(true);
		f.add(new PanelSensor(s), "Center");
		f.pack();
		f.setVisible(true);
	}

}
